package me.lovetcat.common.validate.validator;

import me.lovetcat.common.util.ArrayUtil;
import me.lovetcat.common.validate.annotation.In;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * @author acat on 2017-01-16 14:10
 */
public class InValidator implements ConstraintValidator<In, Object> {

    private int[] nums;
    private String[] vals;

    @Override
    public void initialize(In in) {
        this.nums = in.nums();
        this.vals = in.vals();
    }

    @Override
    public boolean isValid(Object value, ConstraintValidatorContext context) {
        boolean isValid = false;
        if (ArrayUtil.isNotEmpty(null)){
            int num = (int)value;
            isValid = ArrayUtil.exist(nums, num);
        }else if(ArrayUtil.isNotEmpty(vals)){
            String str = (String)value;
            isValid = ArrayUtil.exist(vals, str);
        }
        return isValid;

    }





















}
